	<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="${pageContext.request.contextPath}/jslib/My97DatePicker/WdatePicker.js"></script>
<jsp:include page="../inc.jsp"></jsp:include>

<script type="text/javascript" charset="0.00">
	var datagrid;
	var auth = "${auths}";
	var buttons = [];
	$(function() {
		$('form input').bind('keyup', function(event) {/* 增加回车提交功能 */
			if (event.keyCode == '13') {
				_search();
			}
		});
		if(auth=="all"){
			buttons.push({text : '增加',iconCls : 'icon-add',handler : function() {append();}});
			buttons.push('-');
			buttons.push({text : '删除',iconCls : 'icon-remove',handler : function() {remove();}});
			buttons.push('-');
			buttons.push({text : '编辑',iconCls : 'icon-edit',handler : function() {edit();}});
			buttons.push('-');
			buttons.push({text : '取消选中',iconCls : 'icon-undo',handler : function() {datagrid.datagrid('clearSelections');datagrid.datagrid('unselectAll');}});
			buttons.push('-');
			buttons.push({text : '查看消费记录',handler : function() {checkSale();}});
			buttons.push('-'); 
//			buttons.push({text : '导入导出',handler : function() {impexp();}});
//			buttons.push('-');
// 			buttons.push( {text : '查看积分记录',handler : function() {checkPoint();}});
// 			buttons.push('-');
		}else if(auth!=""){
			var auths = auth.split(",");
			if(auths.length>0){
				for(var i=0;i<auths.length;i++){
					if(auths[i]=="HYGL_HYGL_ADD"){
						buttons.push({text : '增加',iconCls : 'icon-add',handler : function() {append();}});
						buttons.push('-');
					}else if(auths[i]=="HYGL_HYGL_DELETE"){
						buttons.push({text : '删除',iconCls : 'icon-remove',handler : function() {remove();}});
						buttons.push('-');
					}else if(auths[i]=="HYGL_HYGL_EDIT"){
						buttons.push({text : '编辑',iconCls : 'icon-edit',handler : function() {edit();}});
						buttons.push('-');
					}else if(auths[i]=="HYGL_HYGL_CUSUME"){
						buttons.push({text : '查看消费记录',handler : function() {checkSale();}});
						buttons.push('-');
//					}else if(auths[i]=="HYGL_HYGL_DAORUDAOCHU"){
////						buttons.push({text : '导出',handler : function() {impexp();}});
//						buttons.push('-');
//					}
// 					else if(auths[i]=="HYGL_HYGL_POINT"){
// 						buttons.push( {text : '查看积分记录',handler : function() {checkPoint();}});
// 						buttons.push('-');
 					}
			}
				buttons.push({text : '取消选中',iconCls : 'icon-undo',handler : function() {datagrid.datagrid('clearSelections');datagrid.datagrid('unselectAll');}});
				buttons.push('-');
				
				buttons.push({text : '导出数据',handler : function() {
					window.location.href="${pageContext.request.contextPath}/hygl/memberAction!export.html";
				}});
			}
		}
		datagrid = $('#datagrid').datagrid({
			url : 'memberAction!datagrid.html',
			title : '会员列表',
			iconCls : 'icon-save',
			pagination : true,
			pagePosition : 'bottom',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40 ],
			fit : true,
			fitColumns : false,
			nowrap : false,
			border : false,
			idField : 'id',
			sortName : 'serial',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			singleSelect : true,
			frozenColumns : [ [ {
				title : '编号',
				field : 'id',
				width : 100,
				sortable : true,
				checkbox : true
			}, {
				title : '会员编号',
				field : 'serial',
				width : 120,
				sortable : true
			} ] ],
			columns : [ [ {
				title : '所属经销商ID',
				field : 'uid',
				sortable : true,
				width : 10,
				hidden : true
			}, {
				title : '所属经销商',
				field : 'uname',
				sortable : false,
				width : 80,
				align:'center',
				hidden:true	
			},{
				title:'所属仓库',
				field:'repertoryName',
				sortable : false,
				width : 80,
				align:'center'
			},
			{
				title:'所属仓库id',
				field:'rid',
				sortable : false,
				width : 80,
				align:'center',
				hidden:true	
			},	
			{
				title : '会员姓名',
				field : 'name',
				width : 80,
				align:'center'
			},  {
				title : '会员类型ID',
				field : 'tid',
				sortable : false,
				width : 150,
				hidden : true
			}, {
				title : '会员类型',
				field : 'tname',
				sortable : false,
				width : 80,
				align:'center'
			},{
				title : '手机',
				field : 'mobile',
				sortable : true,
				width : 100,
				align:'center'
			},{
				title : '开卡时间',
				field : 'openDate',
				sortable : true,
				width : 135,
				align:'center'
			},{
				title : '生日',
				field : 'birthdayA',
				sortable : true,
				width : 135,
				align:'center'
			},{
				title : '消费金额',
				field : 'consume',
				sortable : true,
				width : 100,
				align:'center'
			},{
				title : '积分',
				field : 'point',
				sortable : true,
				width : 100,
				align:'center'
			},{
				title : '所属商店',
				field : 'storename',
				width : 150,
				hidden : true
			},{
				title : '备注',
				field : 'remark',
				width : 150,
				hidden : true
			},{
				title : '地址',
				field : 'address',
				width : 150,
				hidden : true
			}] ],
			toolbar : buttons
			/*,
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}*/
		});
		var tid0 = $('#searchForm').find('input[name=tid]');
		var tid0Combobox = tid0.combobox({
			url : '${pageContext.request.contextPath}/hygl/memberTypeAction!noAuth_combobox.html',
			valueField : 'id',
			textField : 'name',
			multiple : false,
			editable : false,
			panelHeight : 'auto'
		});

		var rid0 = $('#searchForm').find('input[name=rid]');
		var rid0Combobox = rid0.combobox({
			url : '/jxc/rkgl/repertoryAction!noAuth_combobox2.html',
			valueField : 'id',
			textField : 'name',
			multiple : false,
			editable : false,
			onLoadSuccess : function() {
// 			var sa = 'null';
// 				if(sa!='null'&&sa!='undefinded'&&sa!=null){ 
// 				   rid0.combobox('setValue','null');
// 				}
				parent.$.messager.progress('close');
			}
		});
		

	});
	
/*	function impexp(){
		var p = parent.sy.dialog({
			title : '导入导出',
				href : '${pageContext.request.contextPath}/hygl/memberAction!memberImpExp.html',
				width : 300,
				height : 200
		}); 
	}*/
	
	function edit() {
		var rows = datagrid.datagrid('getSelections');
		if (rows.length == 1) {
			var p = parent.sy.dialog({
				title : '编辑会员',
				href : '${pageContext.request.contextPath}/hygl/memberAction!memberEdit.html',
				width : 500,
				height : 300,
				buttons : [ {
					text : '编辑',
					handler : function() {
						var f = p.find('form');
						f.form('submit', {
							url : '${pageContext.request.contextPath}/hygl/memberAction!edit.html',
							success : function(d) {
								var json = $.parseJSON(d);
								if (json.success) {
									datagrid.datagrid('reload');
									p.dialog('close');
								}
								parent.sy.messagerShow({
									msg : json.msg,
									title : '提示'
								});
							}
						});
					}
				} ],
				onLoad : function() {
				//alert(rows[0].tid);
					var f = p.find('form');
					var tid = f.find('input[name=tid]');
					var tidCombobox = tid.combobox({
						url : '${pageContext.request.contextPath}/hygl/memberTypeAction!noAuth_combobox.html',
						valueField : 'id',
						textField : 'name',
						multiple : false,
						editable : false,
						panelHeight : 'auto',
						onLoadSuccess : function() {
							parent.$.messager.progress('close');
						}
					});
					var rid = f.find('input[name=rid]');
					var ridCombobox = rid.combobox({
						url : '${pageContext.request.contextPath}/rkgl/repertoryAction!noAuth_combobox.html',
						valueField : 'id',
						textField : 'name',
						multiple : false,
						editable : false,
						panelHeight : 'auto',
						onLoadSuccess : function() {
							parent.$.messager.progress('close');
						}
					});
					f.form('load', {
						id : rows[0].id,
						serial : rows[0].serial,
						uid : rows[0].uid,
						name : rows[0].name,
						openDate : rows[0].openDate,
						tid : rows[0].tid,
						storename: rows[0].storename,
						mobile : rows[0].mobile,
						birthdayA : rows[0].birthdayA,
						consume : rows[0].consume,
						point : rows[0].point,
						address : rows[0].address,
						remark : rows[0].remark,
						rid:rows[0].rid
					});
					parent.$.messager.progress('close');
				}
			});
		} else if (rows.length > 1) {
			parent.sy.messagerAlert('提示', '同一时间只能编辑一条记录！', 'error');
		} else {
			parent.sy.messagerAlert('提示', '请选择要编辑的记录！', 'error');
		}
	}
	function append() {
		var p = parent.sy.dialog({
			title : '添加会员',
			href : '${pageContext.request.contextPath}/hygl/memberAction!memberAdd.html',
			width : 500,
			height : 300,
			buttons : [ {
				text : '添加',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/hygl/memberAction!add.html',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				parent.$.messager.progress('close');
				var f = p.find('form');
				var tid = f.find('input[name=tid]');
				var tidCombobox = tid.combobox({
					url : '${pageContext.request.contextPath}/hygl/memberTypeAction!noAuth_combobox.html',
					valueField : 'id',
					textField : 'name',
					multiple : false,
					editable : false,
					panelHeight : 'auto'
				});
		
			    var rid = f.find('input[name=rid]');
					var ridCombobox = rid.combobox({
						url : '${pageContext.request.contextPath}/rkgl/repertoryAction!noAuth_combobox.html',
						valueField : 'id',
						textField : 'name',
						multiple : false,
						editable : false,
						onLoadSuccess : function() {
							if('${sessionInfo.repertoryIds}'!=null&&'${sessionInfo.repertoryIds}'!='null'){
								$.ajax({
									url : '${pageContext.request.contextPath}/rkgl/repertoryAction!noAuth_combobox.html',
									type : "POST",
									success : function(d){
										 var json = $.parseJSON(d);
										 rid.combobox('setValue',json[0].name);
									}
							    });
							    $.ajax({
									url : '${pageContext.request.contextPath}/serial!noAuth_serial.html',
									data : {type : 'HY',rid : ${sessionInfo.repertoryIds}},
									type : "POST",
									success : function(d){
										f.form('load', {
											serial : d
										});
									}
								});
							}
							parent.$.messager.progress('close');
						},
					      onSelect : function(record){ 
						    if(record.id!=null){
						    	$.ajax({
									url : '${pageContext.request.contextPath}/serial!noAuth_serial.html',
									data : {type : 'HY',rid : record.id},
									type : "POST",
									success : function(d){
										f.form('load', {
											serial : d
										});
									}
								});
						    }
						 }
					});  
					
			}
		});
	}
	function remove() {
		var rows = datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.sy.messagerConfirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].id);
					}
					$.ajax({
						url : '${pageContext.request.contextPath}/hygl/memberAction!delete.html',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							parent.sy.messagerShow({
								title : '提示',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.sy.messagerAlert('提示', '请勾选要删除的记录！', 'error');
		}
	}

	function checkSale() {
		var rows = datagrid.datagrid('getSelections');
		if (rows.length == 1) {
			var node = {id:'HYGL_HYGL_XFJL',text:'会员消费记录',state:'open',attributes:{url:'/hygl/memberAction!saleRecord.html?model.id='+rows[0].id}};
			if (parent.centerTabs.tabs('exists', node.text)) {
				parent.centerTabs.tabs('close', node.text);
				parent.addTab(node);
			}else{
				parent.addTab(node);
			}
		} else if (rows.length > 1) {
			parent.sy.messagerAlert('提示', '同一时间只能查看一条记录！', 'error');
		} else {
			parent.sy.messagerAlert('提示', '请选择要查看的记录！', 'error');
		}
	}

	function checkPoint() {
		var rows = datagrid.datagrid('getSelections');
		if (rows.length == 1) {
			var node = {id:'HYGL_HYGL_JFJL',text:'会员积分记录',state:'open',attributes:{url:'/hygl/memberAction!pointRecord.html?model.id='+rows[0].id}};
			if (parent.centerTabs.tabs('exists', node.text)) {
				parent.closeTab(node);
				parent.addTab(node);
			}else{
				parent.addTab(node);
			}
		} else if (rows.length > 1) {
			parent.sy.messagerAlert('提示', '同一时间只能查看一条记录！', 'error');
		} else {
			parent.sy.messagerAlert('提示', '请选择要查看的记录！', 'error');
		}
	}
	

	
	function _search() {
		datagrid.datagrid('load', sy.serializeObject($('#searchForm')));
	}
	function cleanSearch() {
		datagrid.datagrid('load', {});
		$('#searchForm input').val('');
	}

	//清空搜索
	function clean(){
		$('#searchForm input').val('');
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north',border:false,title:'搜索条件'" style="height: 150px;overflow: hidden;" align="left">
		<form id="searchForm">
			<table class="tableForm datagrid-toolbar" style="width: 100%;height: 100%;">
				<tr>
					<th>会员手机</th>
					<td><input name="mobile" style="width:200px;" /></td>
					<th>会员姓名</th>
					<td><input name="name" style="width:220px;" /></td>
					
				</tr>
				<tr>
					<th>会员类型</th>
					<td><input name="tid" style="width:200px;" /></td>
					<th>消费金额</th>
					<td><input name="consumeStart"   style="width: 100px;" />
					至<input name="consumeEnd"  style="width: 100px;" />
					</td> 
				</tr>
				
				<tr>
					<th>所属仓库</th>
					<td><input id="rid" name="rid" style="width: 200px"/></td>	
				</tr>
				 
				<tr>
					<td colspan="4" align="center">
					<center>
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="_search();">搜索</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="clean();">清空</a> 
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="cleanSearch();">取消</a>
					</center>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div data-options="region:'center',border:false" style="overflow: hidden;">
		<table id="datagrid"></table>
	</div>

	<div id="menu" class="easyui-menu" style="width:120px;display: none;">
		<k:security key="HYGL_HYGL_ADD">
			<div onclick="append();" data-options="iconCls:'icon-add'">增加</div>
		</k:security>
		<k:security key="HYGL_HYGL_DELETE">
			<div onclick="remove();" data-options="iconCls:'icon-remove'">删除</div>
		</k:security>
		<k:security key="HYGL_HYGL_EDIT">
			<div onclick="edit();" data-options="iconCls:'icon-edit'">编辑</div>
		</k:security>
		<k:security key="HYGL_HYGL_CUSUME">
			<div onclick="checkSale();" data-options="iconCls:'icon-edit'">查看消费记录</div>
		</k:security>
		<k:security key="HYGL_HYGL_POINT">
			<div onclick="checkPoint();" data-options="iconCls:'icon-edit'">查看积分记录</div>
		</k:security>
	<!--	<k:security key="HYGL_HYGL_DAORUDAOCHU">
			<div onclick="impexp()" data-options="iconCls:'icon-edit'">导入导出</div>
		</k:security> -->
	</div>
</body>
</html>